package com.atkxp.sys.handler;

import com.alibaba.fastjson2.JSON;
import com.atkxp.sys.entity.Result;
import com.atkxp.sys.utils.WebUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author longhunpomie
 * @declaration
 * @email 3314028177@qq.com
 * @create 2023/9/15-19:37
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        Result<Object> fail = Result.fail(20003, "你未拥有此权限，请联系管理员获取权限");

        WebUtils.renderString(httpServletResponse, JSON.toJSONString(fail));
    }
}
